{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n# Artist tutorial\n\n\nUsing Artist objects to render on the canvas.\n\nThere are three layers to the matplotlib API.\n\n* the :class:`matplotlib.backend_bases.FigureCanvas` is the area onto which\n  the figure is drawn\n* the :class:`matplotlib.backend_bases.Renderer` is\n  the object which knows how to draw on the\n  :class:`~matplotlib.backend_bases.FigureCanvas`\n* and the :class:`matplotlib.artist.Artist` is the object that knows how to use\n  a renderer to paint onto the canvas.\n\nThe :class:`~matplotlib.backend_bases.FigureCanvas` and\n:class:`~matplotlib.backend_bases.Renderer` handle all the details of\ntalking to user interface toolkits like `wxPython\n<https://www.wxpython.org>`_ or drawing languages like PostScript®, and\nthe ``Artist`` handles all the high level constructs like representing\nand laying out the figure, text, and lines.  The typical user will\nspend 95% of their time working with the ``Artists``.\n\nThere are two types of ``Artists``: primitives and containers.  The primitives\nrepresent the standard graphical objects we want to paint onto our canvas:\n:class:`~matplotlib.lines.Line2D`, :class:`~matplotlib.patches.Rectangle`,\n:class:`~matplotlib.text.Text`, :class:`~matplotlib.image.AxesImage`, etc., and\nthe containers are places to put them (:class:`~matplotlib.axis.Axis`,\n:class:`~matplotlib.axes.Axes` and :class:`~matplotlib.figure.Figure`).  The\nstandard use is to create a :class:`~matplotlib.figure.Figure` instance, use\nthe ``Figure`` to create one or more :class:`~matplotlib.axes.Axes` or\n:class:`~matplotlib.axes.Subplot` instances, and use the ``Axes`` instance\nhelper methods to create the primitives.  In the example below, we create a\n``Figure`` instance using :func:`matplotlib.pyplot.figure`, which is a\nconvenience method for instantiating ``Figure`` instances and connecting them\nwith your user interface or drawing toolkit ``FigureCanvas``.  As we will\ndiscuss below, this is not necessary -- you can work directly with PostScript,\nPDF Gtk+, or wxPython ``FigureCanvas`` instances, instantiate your ``Figures``\ndirectly and connect them yourselves -- but since we are focusing here on the\n``Artist`` API we'll let :mod:`~matplotlib.pyplot` handle some of those details\nfor us::\n\n    import matplotlib.pyplot as plt\n    fig = plt.figure()\n    ax = fig.add_subplot(2, 1, 1) # two rows, one column, first plot\n\nThe :class:`~matplotlib.axes.Axes` is probably the most important\nclass in the matplotlib API, and the one you will be working with most\nof the time.  This is because the ``Axes`` is the plotting area into\nwhich most of the objects go, and the ``Axes`` has many special helper\nmethods (:meth:`~matplotlib.axes.Axes.plot`,\n:meth:`~matplotlib.axes.Axes.text`,\n:meth:`~matplotlib.axes.Axes.hist`,\n:meth:`~matplotlib.axes.Axes.imshow`) to create the most common\ngraphics primitives (:class:`~matplotlib.lines.Line2D`,\n:class:`~matplotlib.text.Text`,\n:class:`~matplotlib.patches.Rectangle`,\n:class:`~matplotlib.image.Image`, respectively).  These helper methods\nwill take your data (e.g., ``numpy`` arrays and strings) and create\nprimitive ``Artist`` instances as needed (e.g., ``Line2D``), add them to\nthe relevant containers, and draw them when requested.  Most of you\nare probably familiar with the :class:`~matplotlib.axes.Subplot`,\nwhich is just a special case of an ``Axes`` that lives on a regular\nrows by columns grid of ``Subplot`` instances.  If you want to create\nan ``Axes`` at an arbitrary location, simply use the\n:meth:`~matplotlib.figure.Figure.add_axes` method which takes a list\nof ``[left, bottom, width, height]`` values in 0-1 relative figure\ncoordinates::\n\n    fig2 = plt.figure()\n    ax2 = fig2.add_axes([0.15, 0.1, 0.7, 0.3])\n\nContinuing with our example::\n\n    import numpy as np\n    t = np.arange(0.0, 1.0, 0.01)\n    s = np.sin(2*np.pi*t)\n    line, = ax.plot(t, s, color='blue', lw=2)\n\nIn this example, ``ax`` is the ``Axes`` instance created by the\n``fig.add_subplot`` call above (remember ``Subplot`` is just a\nsubclass of ``Axes``) and when you call ``ax.plot``, it creates a\n``Line2D`` instance and adds it to the :attr:`Axes.lines\n<matplotlib.axes.Axes.lines>` list.  In the interactive `ipython\n<http://ipython.org/>`_ session below, you can see that the\n``Axes.lines`` list is length one and contains the same line that was\nreturned by the ``line, = ax.plot...`` call:\n\n.. sourcecode:: ipython\n\n    In [101]: ax.lines[0]\n    Out[101]: <matplotlib.lines.Line2D instance at 0x19a95710>\n\n    In [102]: line\n    Out[102]: <matplotlib.lines.Line2D instance at 0x19a95710>\n\nIf you make subsequent calls to ``ax.plot`` (and the hold state is \"on\"\nwhich is the default) then additional lines will be added to the list.\nYou can remove lines later simply by calling the list methods; either\nof these will work::\n\n    del ax.lines[0]\n    ax.lines.remove(line)  # one or the other, not both!\n\nThe Axes also has helper methods to configure and decorate the x-axis\nand y-axis tick, tick labels and axis labels::\n\n    xtext = ax.set_xlabel('my xdata') # returns a Text instance\n    ytext = ax.set_ylabel('my ydata')\n\nWhen you call :meth:`ax.set_xlabel <matplotlib.axes.Axes.set_xlabel>`,\nit passes the information on the :class:`~matplotlib.text.Text`\ninstance of the :class:`~matplotlib.axis.XAxis`.  Each ``Axes``\ninstance contains an :class:`~matplotlib.axis.XAxis` and a\n:class:`~matplotlib.axis.YAxis` instance, which handle the layout and\ndrawing of the ticks, tick labels and axis labels.\n\nTry creating the figure below.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\nimport matplotlib.pyplot as plt\n\nfig = plt.figure()\nfig.subplots_adjust(top=0.8)\nax1 = fig.add_subplot(211)\nax1.set_ylabel('volts')\nax1.set_title('a sine wave')\n\nt = np.arange(0.0, 1.0, 0.01)\ns = np.sin(2*np.pi*t)\nline, = ax1.plot(t, s, color='blue', lw=2)\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nax2 = fig.add_axes([0.15, 0.1, 0.7, 0.3])\nn, bins, patches = ax2.hist(np.random.randn(1000), 50,\n                            facecolor='yellow', edgecolor='yellow')\nax2.set_xlabel('time (s)')\n\nplt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\nCustomizing your objects\n========================\n\nEvery element in the figure is represented by a matplotlib\n:class:`~matplotlib.artist.Artist`, and each has an extensive list of\nproperties to configure its appearance.  The figure itself contains a\n:class:`~matplotlib.patches.Rectangle` exactly the size of the figure,\nwhich you can use to set the background color and transparency of the\nfigures.  Likewise, each :class:`~matplotlib.axes.Axes` bounding box\n(the standard white box with black edges in the typical matplotlib\nplot, has a ``Rectangle`` instance that determines the color,\ntransparency, and other properties of the Axes.  These instances are\nstored as member variables :attr:`Figure.patch\n<matplotlib.figure.Figure.patch>` and :attr:`Axes.patch\n<matplotlib.axes.Axes.patch>` (\"Patch\" is a name inherited from\nMATLAB, and is a 2D \"patch\" of color on the figure, e.g., rectangles,\ncircles and polygons).  Every matplotlib ``Artist`` has the following\nproperties\n\n==========   ================================================================================\nProperty     Description\n==========   ================================================================================\nalpha        The transparency - a scalar from 0-1\nanimated     A boolean that is used to facilitate animated drawing\naxes         The axes that the Artist lives in, possibly None\nclip_box     The bounding box that clips the Artist\nclip_on      Whether clipping is enabled\nclip_path    The path the artist is clipped to\ncontains     A picking function to test whether the artist contains the pick point\nfigure       The figure instance the artist lives in, possibly None\nlabel        A text label (e.g., for auto-labeling)\npicker       A python object that controls object picking\ntransform    The transformation\nvisible      A boolean whether the artist should be drawn\nzorder       A number which determines the drawing order\nrasterized   Boolean; Turns vectors into raster graphics (for compression & eps transparency)\n==========   ================================================================================\n\nEach of the properties is accessed with an old-fashioned setter or\ngetter (yes we know this irritates Pythonistas and we plan to support\ndirect access via properties or traits but it hasn't been done yet).\nFor example, to multiply the current alpha by a half::\n\n    a = o.get_alpha()\n    o.set_alpha(0.5*a)\n\nIf you want to set a number of properties at once, you can also use\nthe ``set`` method with keyword arguments.  For example::\n\n    o.set(alpha=0.5, zorder=2)\n\nIf you are working interactively at the python shell, a handy way to\ninspect the ``Artist`` properties is to use the\n:func:`matplotlib.artist.getp` function (simply\n:func:`~matplotlib.pyplot.getp` in pyplot), which lists the properties\nand their values.  This works for classes derived from ``Artist`` as\nwell, e.g., ``Figure`` and ``Rectangle``.  Here are the ``Figure`` rectangle\nproperties mentioned above:\n\n.. sourcecode:: ipython\n\n    In [149]: matplotlib.artist.getp(fig.patch)\n\talpha = 1.0\n\tanimated = False\n\tantialiased or aa = True\n\taxes = None\n\tclip_box = None\n\tclip_on = False\n\tclip_path = None\n\tcontains = None\n\tedgecolor or ec = w\n\tfacecolor or fc = 0.75\n\tfigure = Figure(8.125x6.125)\n\tfill = 1\n\thatch = None\n\theight = 1\n\tlabel =\n\tlinewidth or lw = 1.0\n\tpicker = None\n\ttransform = <Affine object at 0x134cca84>\n\tverts = ((0, 0), (0, 1), (1, 1), (1, 0))\n\tvisible = True\n\twidth = 1\n\twindow_extent = <Bbox object at 0x134acbcc>\n\tx = 0\n\ty = 0\n\tzorder = 1\n\nThe docstrings for all of the classes also contain the ``Artist``\nproperties, so you can consult the interactive \"help\" or the\n`artist-api` for a listing of properties for a given object.\n\n\nObject containers\n=================\n\n\nNow that we know how to inspect and set the properties of a given\nobject we want to configure, we need to know how to get at that object.\nAs mentioned in the introduction, there are two kinds of objects:\nprimitives and containers.  The primitives are usually the things you\nwant to configure (the font of a :class:`~matplotlib.text.Text`\ninstance, the width of a :class:`~matplotlib.lines.Line2D`) although\nthe containers also have some properties as well -- for example the\n:class:`~matplotlib.axes.Axes` :class:`~matplotlib.artist.Artist` is a\ncontainer that contains many of the primitives in your plot, but it\nalso has properties like the ``xscale`` to control whether the xaxis\nis 'linear' or 'log'.  In this section we'll review where the various\ncontainer objects store the ``Artists`` that you want to get at.\n\n\nFigure container\n----------------\n\nThe top level container ``Artist`` is the\n:class:`matplotlib.figure.Figure`, and it contains everything in the\nfigure.  The background of the figure is a\n:class:`~matplotlib.patches.Rectangle` which is stored in\n:attr:`Figure.patch <matplotlib.figure.Figure.patch>`.  As\nyou add subplots (:meth:`~matplotlib.figure.Figure.add_subplot`) and\naxes (:meth:`~matplotlib.figure.Figure.add_axes`) to the figure\nthese will be appended to the :attr:`Figure.axes\n<matplotlib.figure.Figure.axes>`.  These are also returned by the\nmethods that create them:\n\n.. sourcecode:: ipython\n\n    In [156]: fig = plt.figure()\n\n    In [157]: ax1 = fig.add_subplot(211)\n\n    In [158]: ax2 = fig.add_axes([0.1, 0.1, 0.7, 0.3])\n\n    In [159]: ax1\n    Out[159]: <matplotlib.axes.Subplot instance at 0xd54b26c>\n\n    In [160]: print(fig.axes)\n    [<matplotlib.axes.Subplot instance at 0xd54b26c>, <matplotlib.axes.Axes instance at 0xd3f0b2c>]\n\nBecause the figure maintains the concept of the \"current axes\" (see\n:meth:`Figure.gca <matplotlib.figure.Figure.gca>` and\n:meth:`Figure.sca <matplotlib.figure.Figure.sca>`) to support the\npylab/pyplot state machine, you should not insert or remove axes\ndirectly from the axes list, but rather use the\n:meth:`~matplotlib.figure.Figure.add_subplot` and\n:meth:`~matplotlib.figure.Figure.add_axes` methods to insert, and the\n:meth:`~matplotlib.figure.Figure.delaxes` method to delete.  You are\nfree however, to iterate over the list of axes or index into it to get\naccess to ``Axes`` instances you want to customize.  Here is an\nexample which turns all the axes grids on::\n\n    for ax in fig.axes:\n        ax.grid(True)\n\n\nThe figure also has its own text, lines, patches and images, which you\ncan use to add primitives directly.  The default coordinate system for\nthe ``Figure`` will simply be in pixels (which is not usually what you\nwant) but you can control this by setting the transform property of\nthe ``Artist`` you are adding to the figure.\n\n.. TODO: Is that still true?\n\nMore useful is \"figure coordinates\" where (0, 0) is the bottom-left of\nthe figure and (1, 1) is the top-right of the figure which you can\nobtain by setting the ``Artist`` transform to :attr:`fig.transFigure\n<matplotlib.figure.Figure.transFigure>`:\n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib.lines as lines\n\nfig = plt.figure()\n\nl1 = lines.Line2D([0, 1], [0, 1], transform=fig.transFigure, figure=fig)\nl2 = lines.Line2D([0, 1], [1, 0], transform=fig.transFigure, figure=fig)\nfig.lines.extend([l1, l2])\n\nplt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here is a summary of the Artists the figure contains\n\n.. TODO: Add xrefs to this table\n\n================ ===============================================================\nFigure attribute Description\n================ ===============================================================\naxes             A list of Axes instances (includes Subplot)\npatch            The Rectangle background\nimages           A list of FigureImages patches - useful for raw pixel display\nlegends          A list of Figure Legend instances (different from Axes.legends)\nlines            A list of Figure Line2D instances (rarely used, see Axes.lines)\npatches          A list of Figure patches (rarely used, see Axes.patches)\ntexts            A list Figure Text instances\n================ ===============================================================\n\n\nAxes container\n--------------\n\nThe :class:`matplotlib.axes.Axes` is the center of the matplotlib\nuniverse -- it contains the vast majority of all the ``Artists`` used\nin a figure with many helper methods to create and add these\n``Artists`` to itself, as well as helper methods to access and\ncustomize the ``Artists`` it contains.  Like the\n:class:`~matplotlib.figure.Figure`, it contains a\n:class:`~matplotlib.patches.Patch`\n:attr:`~matplotlib.axes.Axes.patch` which is a\n:class:`~matplotlib.patches.Rectangle` for Cartesian coordinates and a\n:class:`~matplotlib.patches.Circle` for polar coordinates; this patch\ndetermines the shape, background and border of the plotting region::\n\n    ax = fig.add_subplot(111)\n    rect = ax.patch  # a Rectangle instance\n    rect.set_facecolor('green')\n\nWhen you call a plotting method, e.g., the canonical\n:meth:`~matplotlib.axes.Axes.plot` and pass in arrays or lists of\nvalues, the method will create a :meth:`matplotlib.lines.Line2D`\ninstance, update the line with all the ``Line2D`` properties passed as\nkeyword arguments, add the line to the :attr:`Axes.lines\n<matplotlib.axes.Axes.lines>` container, and returns it to you:\n\n.. sourcecode:: ipython\n\n    In [213]: x, y = np.random.rand(2, 100)\n\n    In [214]: line, = ax.plot(x, y, '-', color='blue', linewidth=2)\n\n``plot`` returns a list of lines because you can pass in multiple x, y\npairs to plot, and we are unpacking the first element of the length\none list into the line variable.  The line has been added to the\n``Axes.lines`` list:\n\n.. sourcecode:: ipython\n\n    In [229]: print(ax.lines)\n    [<matplotlib.lines.Line2D instance at 0xd378b0c>]\n\nSimilarly, methods that create patches, like\n:meth:`~matplotlib.axes.Axes.bar` creates a list of rectangles, will\nadd the patches to the :attr:`Axes.patches\n<matplotlib.axes.Axes.patches>` list:\n\n.. sourcecode:: ipython\n\n    In [233]: n, bins, rectangles = ax.hist(np.random.randn(1000), 50, facecolor='yellow')\n\n    In [234]: rectangles\n    Out[234]: <a list of 50 Patch objects>\n\n    In [235]: print(len(ax.patches))\n\nYou should not add objects directly to the ``Axes.lines`` or\n``Axes.patches`` lists unless you know exactly what you are doing,\nbecause the ``Axes`` needs to do a few things when it creates and adds\nan object.  It sets the figure and axes property of the ``Artist``, as\nwell as the default ``Axes`` transformation (unless a transformation\nis set).  It also inspects the data contained in the ``Artist`` to\nupdate the data structures controlling auto-scaling, so that the view\nlimits can be adjusted to contain the plotted data.  You can,\nnonetheless, create objects yourself and add them directly to the\n``Axes`` using helper methods like\n:meth:`~matplotlib.axes.Axes.add_line` and\n:meth:`~matplotlib.axes.Axes.add_patch`.  Here is an annotated\ninteractive session illustrating what is going on:\n\n.. sourcecode:: ipython\n\n    In [262]: fig, ax = plt.subplots()\n\n    # create a rectangle instance\n    In [263]: rect = matplotlib.patches.Rectangle( (1,1), width=5, height=12)\n\n    # by default the axes instance is None\n    In [264]: print(rect.get_axes())\n    None\n\n    # and the transformation instance is set to the \"identity transform\"\n    In [265]: print(rect.get_transform())\n    <Affine object at 0x13695544>\n\n    # now we add the Rectangle to the Axes\n    In [266]: ax.add_patch(rect)\n\n    # and notice that the ax.add_patch method has set the axes\n    # instance\n    In [267]: print(rect.get_axes())\n    Axes(0.125,0.1;0.775x0.8)\n\n    # and the transformation has been set too\n    In [268]: print(rect.get_transform())\n    <Affine object at 0x15009ca4>\n\n    # the default axes transformation is ax.transData\n    In [269]: print(ax.transData)\n    <Affine object at 0x15009ca4>\n\n    # notice that the xlimits of the Axes have not been changed\n    In [270]: print(ax.get_xlim())\n    (0.0, 1.0)\n\n    # but the data limits have been updated to encompass the rectangle\n    In [271]: print(ax.dataLim.bounds)\n    (1.0, 1.0, 5.0, 12.0)\n\n    # we can manually invoke the auto-scaling machinery\n    In [272]: ax.autoscale_view()\n\n    # and now the xlim are updated to encompass the rectangle\n    In [273]: print(ax.get_xlim())\n    (1.0, 6.0)\n\n    # we have to manually force a figure draw\n    In [274]: ax.figure.canvas.draw()\n\n\nThere are many, many ``Axes`` helper methods for creating primitive\n``Artists`` and adding them to their respective containers.  The table\nbelow summarizes a small sampling of them, the kinds of ``Artist`` they\ncreate, and where they store them\n\n==============================   ====================  =======================\nHelper method                    Artist                Container\n==============================   ====================  =======================\nax.annotate - text annotations   Annotate              ax.texts\nax.bar  - bar charts             Rectangle             ax.patches\nax.errorbar - error bar plots    Line2D and Rectangle  ax.lines and ax.patches\nax.fill - shared area            Polygon               ax.patches\nax.hist - histograms             Rectangle             ax.patches\nax.imshow - image data           AxesImage             ax.images\nax.legend - axes legends         Legend                ax.legends\nax.plot - xy plots               Line2D                ax.lines\nax.scatter - scatter charts      PolygonCollection     ax.collections\nax.text - text                   Text                  ax.texts\n==============================   ====================  =======================\n\n\nIn addition to all of these ``Artists``, the ``Axes`` contains two\nimportant ``Artist`` containers: the :class:`~matplotlib.axis.XAxis`\nand :class:`~matplotlib.axis.YAxis`, which handle the drawing of the\nticks and labels.  These are stored as instance variables\n:attr:`~matplotlib.axes.Axes.xaxis` and\n:attr:`~matplotlib.axes.Axes.yaxis`.  The ``XAxis`` and ``YAxis``\ncontainers will be detailed below, but note that the ``Axes`` contains\nmany helper methods which forward calls on to the\n:class:`~matplotlib.axis.Axis` instances so you often do not need to\nwork with them directly unless you want to.  For example, you can set\nthe font color of the ``XAxis`` ticklabels using the ``Axes`` helper\nmethod::\n\n    for label in ax.get_xticklabels():\n        label.set_color('orange')\n\nBelow is a summary of the Artists that the Axes contains\n\n==============    ======================================\nAxes attribute    Description\n==============    ======================================\nartists           A list of Artist instances\npatch             Rectangle instance for Axes background\ncollections       A list of Collection instances\nimages            A list of AxesImage\nlegends           A list of Legend instances\nlines             A list of Line2D instances\npatches           A list of Patch instances\ntexts             A list of Text instances\nxaxis             matplotlib.axis.XAxis instance\nyaxis             matplotlib.axis.YAxis instance\n==============    ======================================\n\n\nAxis containers\n---------------\n\nThe :class:`matplotlib.axis.Axis` instances handle the drawing of the\ntick lines, the grid lines, the tick labels and the axis label.  You\ncan configure the left and right ticks separately for the y-axis, and\nthe upper and lower ticks separately for the x-axis.  The ``Axis``\nalso stores the data and view intervals used in auto-scaling, panning\nand zooming, as well as the :class:`~matplotlib.ticker.Locator` and\n:class:`~matplotlib.ticker.Formatter` instances which control where\nthe ticks are placed and how they are represented as strings.\n\nEach ``Axis`` object contains a :attr:`~matplotlib.axis.Axis.label` attribute\n(this is what :mod:`~matplotlib.pyplot` modifies in calls to\n:func:`~matplotlib.pyplot.xlabel` and :func:`~matplotlib.pyplot.ylabel`) as\nwell as a list of major and minor ticks.  The ticks are\n:class:`~matplotlib.axis.XTick` and :class:`~matplotlib.axis.YTick` instances,\nwhich contain the actual line and text primitives that render the ticks and\nticklabels.  Because the ticks are dynamically created as needed (e.g., when\npanning and zooming), you should access the lists of major and minor ticks\nthrough their accessor methods :meth:`~matplotlib.axis.Axis.get_major_ticks`\nand :meth:`~matplotlib.axis.Axis.get_minor_ticks`.  Although the ticks contain\nall the primitives and will be covered below, ``Axis`` instances have accessor\nmethods that return the tick lines, tick labels, tick locations etc.:\n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots()\naxis = ax.xaxis\naxis.get_ticklocs()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "axis.get_ticklabels()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "note there are twice as many ticklines as labels because by\n default there are tick lines at the top and bottom but only tick\n labels below the xaxis; this can be customized\n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "axis.get_ticklines()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "by default you get the major ticks back\n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "axis.get_ticklines()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "but you can also ask for the minor ticks\n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "axis.get_ticklines(minor=True)\n\n# Here is a summary of some of the useful accessor methods of the ``Axis``\n# (these have corresponding setters where useful, such as\n# set_major_formatter)\n#\n# ======================  =========================================================\n# Accessor method         Description\n# ======================  =========================================================\n# get_scale               The scale of the axis, e.g., 'log' or 'linear'\n# get_view_interval       The interval instance of the axis view limits\n# get_data_interval       The interval instance of the axis data limits\n# get_gridlines           A list of grid lines for the Axis\n# get_label               The axis label - a Text instance\n# get_ticklabels          A list of Text instances - keyword minor=True|False\n# get_ticklines           A list of Line2D instances - keyword minor=True|False\n# get_ticklocs            A list of Tick locations - keyword minor=True|False\n# get_major_locator       The matplotlib.ticker.Locator instance for major ticks\n# get_major_formatter     The matplotlib.ticker.Formatter instance for major ticks\n# get_minor_locator       The matplotlib.ticker.Locator instance for minor ticks\n# get_minor_formatter     The matplotlib.ticker.Formatter instance for minor ticks\n# get_major_ticks         A list of Tick instances for major ticks\n# get_minor_ticks         A list of Tick instances for minor ticks\n# grid                    Turn the grid on or off for the major or minor ticks\n# ======================  =========================================================\n#\n# Here is an example, not recommended for its beauty, which customizes\n# the axes and tick properties\n\n# plt.figure creates a matplotlib.figure.Figure instance\nfig = plt.figure()\nrect = fig.patch  # a rectangle instance\nrect.set_facecolor('lightgoldenrodyellow')\n\nax1 = fig.add_axes([0.1, 0.3, 0.4, 0.4])\nrect = ax1.patch\nrect.set_facecolor('lightslategray')\n\n\nfor label in ax1.xaxis.get_ticklabels():\n    # label is a Text instance\n    label.set_color('red')\n    label.set_rotation(45)\n    label.set_fontsize(16)\n\nfor line in ax1.yaxis.get_ticklines():\n    # line is a Line2D instance\n    line.set_color('green')\n    line.set_markersize(25)\n    line.set_markeredgewidth(3)\n\nplt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\nTick containers\n---------------\n\nThe :class:`matplotlib.axis.Tick` is the final container object in our\ndescent from the :class:`~matplotlib.figure.Figure` to the\n:class:`~matplotlib.axes.Axes` to the :class:`~matplotlib.axis.Axis`\nto the :class:`~matplotlib.axis.Tick`.  The ``Tick`` contains the tick\nand grid line instances, as well as the label instances for the upper\nand lower ticks.  Each of these is accessible directly as an attribute\nof the ``Tick``.\n\n==============   ==========================================================\nTick attribute   Description\n==============   ==========================================================\ntick1line        Line2D instance\ntick2line        Line2D instance\ngridline         Line2D instance\nlabel1           Text instance\nlabel2           Text instance\n==============   ==========================================================\n\nHere is an example which sets the formatter for the right side ticks with\ndollar signs and colors them green on the right side of the yaxis\n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import matplotlib.ticker as ticker\n\n# Fixing random state for reproducibility\nnp.random.seed(19680801)\n\nfig, ax = plt.subplots()\nax.plot(100*np.random.rand(20))\n\nformatter = ticker.FormatStrFormatter('$%1.2f')\nax.yaxis.set_major_formatter(formatter)\n\nfor tick in ax.yaxis.get_major_ticks():\n    tick.label1.set_visible(False)\n    tick.label2.set_visible(True)\n    tick.label2.set_color('green')\n\nplt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
